<script type="text/javascript" >
  $(document).ready(
  function(){
 
    
    $("#typ").change(function(){
      if(($('#typ').val()) == 0){
        $('#datum').show();
        $('#den').hide();
        $('#nove').show();
      }
      else if(($('#typ').val()) == 1){
        $('#datum').hide();
        $('#den').show();
        $('#nove').hide();
      }
      else{
        $('#datum').show();
        $('#den').hide();
        $('#nove').hide();
      }
    } 
  )
    $('#nove').hide();
           
  }
        
);
</script>

<div id="mess"><?php if (isset($mess)) echo $mess; ?></div>
<div id="form">
  <table>
    <?php
    $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
    echo form_open(base_url() . 'user/addevent');

    $event_data = array('name' => 'event_meno',
        'id' => 'event_meno',
        'size' => '20',
        'value' => set_value('event_meno', ''));
    echo "<tr><td>" . form_label('Nazov eventu:', 'event_meno') . '</td><td >' . form_input($event_data) . "</td><td>" . form_error('event_meno') . '</td></tr>';
    $pole = array();

    $selected = 'vyucba';
    echo "<tr><td>" . form_label('Typ eventu:', 'typ') . "</td>
         <td><select name='typ' id='typ'>";
    foreach ($types as $type)
      echo "<option value='" . $type['id'] . "' id='" . $type['id'] . "'>" . $type['event_type'] . "</option>";
    echo "</select></td></tr>";
    echo "<tr id='nove'><td>" . form_label('Názov nového typu:', 'nove') . "</td>";
    $nove_data = array('name' => 'nove',
        'id' => 'nove',
        'size' => '20',
        'value' => set_value('nove', ''));
    echo "<td>" . form_input($nove_data) . "</td>";
    echo "</tr>";

    for ($i = 1; $i < 32; $i++) {
      if ($i < 10)
        $pole_den[$i] = '0' . $i;
      else
        $pole_den[$i] = $i;
    }
    $selected = isset($_POST['datum']) ? $_POST['datum'] : date("j");
    echo "<tr id='datum'><td>" . form_label('Dátum:', 'datum') . "</td><td>" . form_dropdown('datum', $pole_den, $selected);

    for ($i = 1; $i < 13; $i++) {
      if ($i < 10)
        $pole_mes[$i] = '0' . $i;
      else
        $pole_mes[$i] = $i;
    }

    $selected = isset($_POST['mesiac']) ? $_POST['mesiac'] : date("n");
    echo form_dropdown('mesiac', $pole_mes, $selected);

    $selected = date("Y");
    $data[$selected] = isset($_POST['rok']) ? $_POST['rok'] : $selected;
    $data[$selected + 1] = $selected + 1;
    echo form_dropdown('rok', $data, $selected) . "</td></tr>";

    $selected = isset($_POST['den']) ? $_POST['den'] : 'pon';
    $data = array(
        '1' => 'pondelok',
        '2' => 'utorok',
        '3' => 'streda',
        '4' => 'štvrtok',
        '5' => 'piatok'
    );
    echo "<tr id='den'><td>" . form_label('Deň:', 'den') . "</td><td>" . form_dropdown('den', $data, $selected) . "</td></tr>";


    foreach ($rooms as $room) {
      $pole[$room['id']] = $room['room_name'];
    }


    echo "<tr><td>" . form_label('Miestnosť:', 'room') . "</td><td>" . form_dropdown('room', $pole) . "</td></tr>";

    for ($i = 8; $i <= 20; $i++)
      $pole_odhod[$i] = $i;
    $selected = isset($_POST['od_hod']) ? $_POST['od_hod'] : '8';
    echo "<tr><td>" . form_label('Od:', 'od_hod') . "</td><td>" . form_dropdown('od_hod', $pole_odhod, $selected) . ":";

    $pole_odmin['0'] = '00';
    for ($i = 1; $i < 12; $i++)
      $pole_odmin[($i * 5)] = ($i * 5);
    $selected = isset($_POST['od_min']) ? $_POST['od_min'] : 0;
    echo form_dropdown('od_min', $pole_odmin, $selected) . "</td>";

    for ($i = 8; $i <= 20; $i++)
      $pole_dohod[$i] = $i;
    $selected = isset($_POST['do_hod']) ? $_POST['do_hod'] : '8';
    echo "<td>" . form_label('do:', 'do_hod') . form_dropdown('do_hod', $pole_odhod, $selected) . ":";

    $pole_domin['0'] = '00';
    for ($i = 1; $i < 12; $i++)
      $pole_domin[($i * 5)] = ($i * 5);
    $selected = isset($_POST['do_min']) ? $_POST['do_min'] : 0;

    echo form_dropdown('do_min', $pole_domin, $selected) . '</td></tr>';

    echo "<tr id='sub_cell'><td></td><td></td><td>" . form_submit('submit', 'Pridaj event', 'id="submit"') . "</td></tr>";

    echo form_close();
    ?>    
  </table>
</div>
